package com.example.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * TODO
 * 前端响应结果
 * @Comment：最难的一次作业
 * @Date: 2023/11/1
 */
@ApiModel(value = "响应参数")
@Data
public class Result implements Serializable {

    //是否响应成功
    @ApiModelProperty(value = "是否响应成功标识", dataType = "boolean")
    private boolean flag;

    //响应消息
    @ApiModelProperty(value = "响应信息", dataType = "String")
    private String message;

    //响应数据
    @ApiModelProperty(value = "响应数据", dataType = "Object")
    private Object data;

    public Result() {
    }

    public Result(boolean flag, String message, Object data) {
        this.flag = flag;
        this.message = message;
        this.data = data;
    }

    public Result(boolean flag, String message) {
        this.flag = flag;
        this.message = message;
    }

    //响应成功调用的方法和返回结果
    public static Result success(String message, Object data){
        return new Result(true, message, data);
    }

    //响应成功调用的方法和返回结果
    public static Result success(String message){
        return new Result(true, message);
    }

    //响应失败调用的方法和返回结果
    public static Result fail(String message){
        return new Result(false, message);
    }
}
